//index.js
// 引入 QCloud 小程序增强 SDK
var qcloud = require('../../../vendor/qcloud-weapp-client-sdk/index');

// 引入配置
var config = require('../../../config');

// 显示繁忙提示
var showBusy = text => wx.showToast({
    title: text,
    icon: 'loading',
    duration: 10000
});

// 显示成功提示
var showSuccess = text => {
    wx.hideToast();
    wx.showToast({
        title: text,
        icon: 'success'
    });
};

// 显示失败提示
var showModel = (title, content) => {
    wx.hideToast();

    wx.showModal({
        title,
        content: JSON.stringify(content),
        showCancel: false
    });
};
//获取应用实例
var app = getApp()
Page({
  data: {
    "item":[],
    "item1": {
      "canIUse": wx.canIUse('button.open-type.contact')
    },
    "hidden":true,
    "active":false
  },
  onLoad: function (e) {
    console.log('onLoad');
    this.setData({
        track_id:e.track_id
    })
    wx.setStorageSync('track_id', e.track_id);
    var self=this;
    qcloud.request({
        // 要请求的地址
        url: 'https://81391412.qbanling.com/api/announcements',
        success(result) {
          console.log(result);
          if(result.data.success==true){
            self.setData({
                item:result.data.data,
                active:true
            });
          }else{
            self.setData({
                active:false
            });
          }
        },

        fail(error) {
            console.log('request fail', error);
        },

        complete() {
            console.log('request complete');
        }
      });
    app.getUserInfo(function(userInfo){
      console.log(userInfo);
      if(self.data.track_id){
        var data={};
        data.track_id=self.data.track_id;
        data.openid=userInfo.openId;
        qcloud.request({
          // 要请求的地址
          url: 'https://81391412.qbanling.com/api/track_logs',
          method:"POST",
          data: data,
          success(result) {
            console.log(result);
          },
          fail(error) {
              console.log('request fail', error);
          },

          complete() {
              console.log('request complete');
          }
        });
      }
    });
  },
  onShow: function () {
    console.log('onShow');
  },
  show:function(){
    var self=this;
    wx.previewImage({
      current: self.data.item[0], // 当前显示图片的http链接
      urls: [self.data.item[0]] // 需要预览的图片http链接列表
    })
    // this.setData({
    //     hidden:false
    // });
  },
  hidden:function(){
  this.setData({
        hidden:true
    });
  },
  onShareAppMessage: function () {
    return {
      title: '密件',
      path: 'pages/person/index/index',
      success: function(res) {
        console.log('1234');
        showSuccess('分享123成功');
        console.log(res);
        // 分享成功
      },
      fail: function(res) {
        // 分享失败
        console.log('1234');
        console.log(res);
      },
      complete:function(res){
        console.log(res);
      }
    }
  }
})
